package mammuthus.web.util

import java.util
import com.webdm.common.tools.DESCoder

import scala.collection.JavaConversions._

/**
 * Created by fengbingjian on 15/5/18 13:21.
 */
object AuthUtil {

  val prefix = "_@#!_mammuthus_"

  val cookieKey = "_t_1_"
  def createKey(userName: String): String = {

    DESCoder.encrypt(prefix +  userName)

  }

  def parseKey(key: String):Tuple2[Boolean, String] = {

    if(key != null && !key.isEmpty){

      val result = DESCoder.decrypt(key)
      if(result != null && result.startsWith(prefix)){

        return (true, result.replace(prefix, ""))
      }
    }
    (false, null)
  }

}
